﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yq.Basis
{
    /// <summary>
    /// AddInParameter辅助
    /// </summary>
    public class ParameterTool
    {
        /// <summary>
        ///判断传入值是不是默认值，如果是返回DBNull.Value，否则返回正常值
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object GetObj(object obj)
        {
            object outobj = obj;

            if (obj == null)
            {
                outobj = DBNull.Value;
            }
            else if (obj is int)
            {
                outobj = Convert.ToInt32(obj) == int.MinValue ? DBNull.Value : obj;
            }
            else if (obj is DateTime)
            {
                outobj = Convert.ToDateTime(obj) == DateTime.MinValue ? DBNull.Value : obj;
            }
            else if (obj is decimal)
            {
                outobj = Convert.ToDecimal(obj) == Decimal.MinValue ? DBNull.Value : obj;
            }

            return outobj;
        }

    }
}
